﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Remoting.Contexts;
using Summer.Core.Aop;
using System.Runtime.Remoting.Activation;

#region License
/*
 *  Copyright (c) Dumuzi.cn 2009 , All rights reserved.
 *  CLR Version:  2.0.50727.4927
 *  NameSpace: Summer.Core.Aop
 *  Author:Edwin Tai,戴佳顺
 *  Msn:edwin19861218@hotmail.com
 *  QQ: 1961218
 *  Date:2009/10/27 16:37:20
 *  Licensed under the Microsoft Public License (Ms-PL)
 *  This license governs use of the accompanying software. 
 *  If you use the software, you accept this license.
 *  If you do not accept the license, do not use the software.
 */
#endregion

namespace Summer.Core.Aop
{
    /// <summary>
    /// Base aopattribute
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public abstract class AbstractAOPAttribute : Attribute, IContextAttribute
    {
        private string m_aspectXml;
        /// <summary>
        /// The default path of config file
        /// </summary>
        private const string DEFAULT_PATH = @"aspect.xml";
        /// <summary>
        /// Attribute Intial
        /// </summary>
        public AbstractAOPAttribute()
        {
            m_aspectXml = DEFAULT_PATH;
        }
        /// <summary>
        /// Attribute Intial
        /// </summary>
        /// <param name="aspectXml">The full path of config file</param>
        public AbstractAOPAttribute(string aspectXml)
        {
            this.m_aspectXml = aspectXml;
        }
        /// <summary>
        /// Get AOPProperty
        /// </summary>
        /// <returns>The instance of AOPProperty</returns>
        protected abstract AbstractAOPProperty GetAOPProperty();

        #region IContextAttribute Members
        /// <summary>
        /// Send context to caller
        /// </summary>
        /// <param name="ctorMsg">target</param>
        public void GetPropertiesForNewContext(IConstructionCallMessage msg)
        {
            AbstractAOPProperty property = GetAOPProperty();
            property.AspectXml = m_aspectXml;
            msg.ContextProperties.Add(property);
        }
        /// <summary>
        /// Whether to create new instance
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="msg">msg</param>
        /// <returns>
        /// If false,create new instance
        /// </returns>
        public bool IsContextOK(Context ctx, IConstructionCallMessage msg)
        {
            return false;
        }
        #endregion
    }
}
